<?php

/**
 *  系统错误日志表
 */

namespace app\admin\service;

use  app\admin\model\SystemErrorLog as ModelSystemErrorLog;

class SystemErrorLog extends BaseService
{
    /**
     *  系统日志列表
    */
    public function list($param = [], $page = 1, $limit = 10)
    {
        $where['type'] = $param['type'];
        $arrData = ['code' => 0, 'message' => 'success'];
        $ModelSystemErrorLog = ModelSystemErrorLog::where($where);
        $total = $ModelSystemErrorLog->count();
        $result = $ModelSystemErrorLog->page($page, $limit)->select();
        $arrData['data'] = ['list' => $result->toArray(), 'total' => $total];
        return $arrData;
    }


    /**
     *  删除日志
    */
    public function delete($param)
    {
        $ids = $param['ids'];

        if(is_array($ids)){
            $arrData = ['code' => 1, 'message' => 'error'];
        }

        $result = ModelSystemErrorLog::where('id','in',$ids)->delete();

        if( $result ) {
            $this->logger->logOperation($ids, 'SystemErrorLog', '删除', '删除日志');
            $arrData = ['code' => 0, 'message' => 'success'];
            return $arrData;
        }

        return $arrData;

    }
}
